import sys
from PyQt5.QtWidgets import QApplication, QWidget, QMessageBox
from PyQt5.QtCore import Qt
 
class MouseClickWidget(QWidget):
    def __init__(self, parent=None):
        super(MouseClickWidget, self).__init__(parent)
 
    def mousePressEvent(self, event):
        if event.button() == Qt.LeftButton:
            # 获取鼠标点击位置
            x = event.pos().x()
            y = event.pos().y()
            # 显示鼠标点击位置
            QMessageBox.information(self, "Mouse Click Position", f"X: {x}, Y: {y}")
 
def main():
    app = QApplication(sys.argv)
    widget = MouseClickWidget()
    widget.resize(300, 200)
    widget.show()
    sys.exit(app.exec_())
 
if __name__ == '__main__':
    main()